<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body{ background-color: #F7F8FA;  }
			.infomation ul{ margin-top: 10px; background-color: #fff;}
			.infomation li{ position: relative; overflow: hidden;font-size:0;}
			.infomation a{ position:relative; padding: 0 15px; background-color: #fff; z-index: 3;}
			.infomation li a::after{ position:absolute; content: ""; left: 15px; right: 0; bottom: 0; border-bottom: 1px #d4d4d4 solid; transform: scaleY(0.5);}
			.infomation .m_cell_ft img{ width: 6px;}
			.infomation i{ display:block; position: relative; padding: 15px 10px 15px 0; font-size:0;}
			.infomation i img{ width: 45px; height: 45px; border-radius: 10px;}
			.infomation em{ position: absolute; right: 5px; top: 10px; border: 0px #fff solid; border-radius: 50%; width: 17px; height: 17px; line-height: 17px; text-align: center; color: #fff; background-color: #f03640; font-size: 11px;}
			.infomation h4{ display:block; position: relative; font-size: 15px; font-weight: 500; color: #000; line-height: 20px;}
			.infomation h4 b{ font-size: 15px; font-weight: 500; color: #000;}
			
			.infomation h4 span{ position: absolute; right: 0; top: 0; font-size: 12px; color: #999; font-weight: 400;}
			.infomation p{ font-size: 12px; color: #9F9F9F; padding-top: 4px; width: 250px; overflow:hidden; text-overflow:ellipsis; white-space: nowrap;}
			.infomation button{ display: block; border: 0; position: absolute; right: 0; top: 0; bottom: 0; background-color: #f03640; color: #fff; font-size: 16px; border-radius: 0; width: 60px; z-index: 1;}
			.infomation li.on a{ transform: translateX(-60px);}
			.wrapper {
				position: relative;
				height: 75px;
				overflow: hidden; 
			}
			.container {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 75px;
				padding: 0 15px;
				box-sizing: border-box;
				background-color: #fff;

				
			}
			.container::after{display:block; position: absolute; content: ""; left: 15px; right: 0; bottom: 0; height: 1px; background-color: #dedede; overflow: hidden; transform: scaleY(0.5);}

			.delete {
				float: right;
				width: 60px;
				top: 0;
				right: 0;
				line-height: 75px;
				background-color: #DD4848;
				color: #fff;
				font-size: 15px;
				font-weight: 400;
				text-align: center;
				height: 75px;
			}
			@keyframes noheight {
				0% {
					height: 75px;
					opacity: 1;
				}

				100% {
					height: 0px;
					opacity: 0;
				}
			}

			.noheight {
				animation: noheight .5s linear 0s forwards;
			}
			.display-none{ display:none; }
			.text-center { text-align: center !important; }
		</style>
	</head>
	<body>
		<!--消息start-->
		<div class="infomation">
		  <ul class="top">
				<a href="javascript:;" tapmode="lipress" onclick="openNavWin('#ddd','sysmsg_win','sysmsg_frm.html','系统消息',false,false,true,[],{});">
					<div class="m_cell_hd"><i><img src="../../image/img_28.png" alt="" /><em id="redpoint" class="display-none">0</em></i></div>
					<div class="m_cell_hd m_cell_primary"><h4>系统消息</h4></div>
					<div class="m_cell_ft"><img src="../../image/img_13.png" alt="" /></div>
				</a>
			</ul>
			<ul class="list" id="chatlist">
			</ul>
			<script id="chatlist_template" type="text/template">
			{{ for (var i = 0, len = it.length; i < len; i++) { }}
				<li>
					<div class="wrapper">
						<div class="container" tapmode data-uid="{{=it[i].uid}}" data-nickname="{{=it[i].nickname}}">
							<div class="m_cell_hd"><i><img onload="fnLoadImage(this)" id="avatar_{{=it[i].uid}}" data-url="{{=it[i].avatar}}" src="../../image/defaultimg.png" />{{? it[i].unreadMessageCount > 0 }}<em id="noread{{=it[i].uid}}">{{=it[i].unreadMessageCount}}</em>{{?}}</i></div>
							<div class="m_cell_hd m_cell_primary">
								<h4><b id="nickname_{{=it[i].uid}}">{{=it[i].nickname}}</b><span>{{=it[i].createtime}}</span></h4>
								<p>{{=it[i].msg}}</p>
							</div>
						</div>
						<div class="delete" onclick="return toDelete(event,this, '{{=it[i].targetId}}');">
							删除
						</div>
					</div>
				</li>
			{{ } }}
			</script>
		</div>
		<!--消息end-->
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/app.js"></script>
	<script type="text/javascript" src="../../script/doT.js"></script>
	<script type="text/javascript">
		var rong,db;
		var myuid,myavatar,mylocalavatar;
		apiready = function() {
			//alert(api.winName+'?'+api.frameName);
			api.parseTapmode();
			db = api.require('db');
			rong = api.require('rongCloud2');
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					myuid = userinfo.mobile;
					myavatar = userinfo.avatar;
					fnLoadMyImage(userinfo.avatar);
					opendb();//初始化db数据库					
				}
			});
			getJsonFromAPI();
			var transformarr = [];
			for(var i=1; i<24; i++)
			{
				var index = i < 10 ? '0'+i : i;
				transformarr.push('widget://image/UIPullRefreshImg/pull_end_image_frame_'+index+'.png');
			}
			api.setCustomRefreshHeaderInfo({
				bgColor : '#F7F8FA',
				image : {
					pull : 'widget://image/UIPullRefreshImg/pull.png',
					transform : transformarr,
					load : transformarr
				}
			}, function(ret, err) {
				getJsonFromAPI();
				setTimeout(function() {
					api.refreshHeaderLoadDone();
				}, 3000)
			});
			api.addEventListener({
				name : 'refreshavatar'
			}, function(ret, err) {
				api.getPrefs({
					key: 'user_info'
				}, function(ret, err) {
					if (ret && ret.value)
					{
						var userinfo = JSON.parse(ret.value);
						myuid = userinfo.mobile;
						myavatar = userinfo.avatar;
						fnLoadMyImage(userinfo.avatar);					
					}
				});				
			});
			api.addEventListener({
				name : 'changeredpoint'
			}, function(ret, err) {
				var msgjson = ret.value.msgjson;
				if(msgjson.sysnoreadmsg == 0)
				{
					//清除个人中心红点
					setredpoint();
				}
				else
				{
					if($api.hasCls($api.byId('redpoint'),'display-none')) {
						$api.removeCls($api.byId('redpoint'),'display-none');
					}
					$api.text($api.byId('redpoint'),msgjson.sysnoreadmsg);
				}
				
			});
			api.addEventListener({
				name : 'new_msg'
			}, function(ret, err) {
				chatdialoglist();//更新会话列表
			});
			api.addEventListener({
				name:"refreshindex"
			},function(ret,err){
				api.getPrefs({
					key: 'user_info'
				}, function(ret, err) {
					if (ret && ret.value)
					{
						var userinfo = JSON.parse(ret.value);
						myuid = userinfo.mobile;
						myavatar = userinfo.avatar;
						fnLoadMyImage(userinfo.avatar);
						opendb();//初始化db数据库	
					}
				});
				getJsonFromAPI();
				chatdialoglist();
			});
			api.addEventListener({
				name : 'chatdialoglist'
			}, function(ret, err) {
				api.getPrefs({
					key: 'user_info'
				}, function(ret, err) {
					if (ret && ret.value)
					{
						var userinfo = JSON.parse(ret.value);
						myuid = userinfo.mobile;
						chatdialoglist();//更新会话列表			
					}
				});
				
			});
			api.addEventListener({
				name : 'refreshsysmsg'
			}, function(ret, err) {
				getJsonFromAPI();
				
			});
			setTimeout(function(){
				chatdialoglist(); //获取会话列表
			}, 1000);
			
		}
		function getJsonFromAPI() {
			//从接口获取查询数据
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret.value) {
					var userinfo = JSON.parse(ret.value);
					
					api.ajax({
						url: ApiUrl + '/v1/msgs/',
						method: 'get',
						cache: false,
						timeout: 10,
						headers: {
							authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
						}
					}, function(ret, err) {
						api.refreshHeaderLoadDone();
						if (ret) {
							
							if(ret.noreadsysmsg == 0)
							{
								//清除个人中心红点
								setredpoint();
							}
							else
							{
								if($api.hasCls($api.byId('redpoint'),'display-none')) {
									$api.removeCls($api.byId('redpoint'),'display-none');
								}
								$api.text($api.byId('redpoint'),ret.noreadsysmsg);
							}
							api.execScript({
								name: 'root',
								frameName: 'home_frm',
								script: 'reloadUnreadCount();'
							});
						} else {
							if(err.statusCode==402)
							{
								Relogin();
							}
							else
							{
								console.log(JSON.stringify(err));
								toast('网络异常，请重试');
							}
						}
					});
				}
			});
			isload = 0;
		}
		function setredpoint() {
			$api.addCls($api.byId('redpoint'),'display-none');
		}
		
		function fnLoadMyImage(dataUrl) {
			if(dataUrl!=''){
				api.imageCache({
					url: dataUrl
				}, function(ret, err) {
				
					if(ret && ret.status == true){
						mylocalavatar = ret.url;
						
					}
				});
			}
		}
		function addDiyEvent() {
			//添加自定义滑到事件
			var liList = $api.domAll('.container');
			// ontouchstart="return touchstartF(event,this);" ontouchmove="return touchmoveF(event,this);"
			for (var i = 0; i < liList.length; i++) {
				$api.addEvt(liList[i], 'touchstart', function(event) {
					//event.preventDefault();阻止click事件
					touchstartF(event,this);
				});
				$api.addEvt(liList[i], 'touchmove', function(event) {
					touchmoveF(event,this);
				});
				$api.addEvt(liList[i], 'click', function(event) {
					var dfuid = $api.attr(this, 'data-uid');
					var avatarid = this.children[0].children[0].getElementsByTagName("img")[0]; //获取头像路径
					var dflocalavatar = $api.attr(avatarid,'src');
					var dfavatar = $api.attr(avatarid,'data-url');
					var dfnickname = $api.attr(this, 'data-nickname');
					var params = {
						dfuid: dfuid,
						dfnickname : dfnickname,
						dflocalavatar : dflocalavatar,
						dfavatar : dfavatar,
						mylocalavatar: mylocalavatar
					};
					//alert(JSON.stringify(params));
					opWin('chat_win','chat_win.html',true,params,false);
					//openNavWin('#ddd','chat_win','chat_frm.html',dfnickname,false,false,true,[],params);
					updaterecord(dfuid);
					$api.remove($api.byId('noread'+dfuid));
					
					
				});
			}
		}
		function fnLoadImage(obj) {
			obj.onload = null;
			
			var dataUrl = $api.attr(obj, 'data-url');
			if(dataUrl!=''){
				api.imageCache({
					url: dataUrl
				}, function(ret, err) {
					if(ret && ret.status == true){
						obj.src = ret.url;
					}
				});
			}
		}
		function fnLoadImagebak(obj) {
			obj.onload = null;
			var mobile = $api.attr(obj.parentNode.parentNode.parentNode, 'data-uid');
			var nickname = $api.attr(obj.parentNode.parentNode.parentNode, 'data-nickname');
			if(nickname == '') {
				//获取头像昵称
				api.getPrefs({
					key: 'user_info'
				}, function(ret, err) {
					if (ret.value) {
						var userinfo = JSON.parse(ret.value);
						api.ajax({
							url: ApiUrl + '/v1/userinfo/'+mobile,
							method: 'get',
							cache: false,
							timeout: 10,
							headers: {
								authorization: kAppKey+';'+userinfo.access_token+';'+userinfo.uid
							}
						}, function(ret, err) {
							if (ret) {
								$api.text($api.byId('nickname_'+mobile),ret.realname)
								$api.attr($api.byId('avatar_'+mobile),'src',ret.avatar)
							}
						});
					}
				});
			}
			else
			{
				var dataUrl = $api.attr(obj, 'data-url');
				if(dataUrl!=''){
					api.imageCache({
						url: dataUrl
					}, function(ret, err) {
						if(ret && ret.status == true){
							obj.src = ret.url;
						}
					});
				}
			}
		}
		//打开数据库
		function opendb() {
			
			db.openDatabase({
				name : 'record'
			}, function(ret, err) {
				if (ret.status) {
					initdb();
				}
			});
		}
		//初始化数据库
		function initdb() {
			db.executeSql({
				name : 'record',
				sql : "CREATE TABLE IF NOT EXISTS 'chatdialogs' ('ID' INTEGER PRIMARY KEY AUTOINCREMENT,'dialogname' VARCHAR(50),'content' TEXT,'createtime' INTEGER)"
			}, function(ret, err) {
				if (ret.status) {
					ReadChatDialog();
				} else {
					api.alert({
						msg : '初始化失败！请重新打开/n' + JSON.stringify(err),
						buttons : ['确定']
					});
				}
			});
		}


		//读取会话记录
		function ReadChatDialog() {
			api.getPrefs({
				key: 'user_info'
			}, function(ret, err) {
				if (ret && ret.value)
				{
					var userinfo = JSON.parse(ret.value);
					myuid = userinfo.mobile;
					
					var dialogname = '#'+myuid+'and';
					//alert("select * from chatdialogs where dialogname like '"+dialogname+"%' order by ID asc");
					db.selectSql({
						name : 'record',
						sql : "select * from chatdialogs where dialogname like '"+dialogname+"%' order by ID asc"
					}, function(ret, err) {
						if (ret) {
						//console.log(JSON.stringify(ret));
						//alert(JSON.stringify(ret));
							if (ret.data != '') {
								var chatdialog = [];
								
								for(var item in ret.data){
									if(ret.data[item])
									{
										var content = ret.data[item].content;
										
										var jsonmsg = $api.strToJson(content); 
									
										var msgtype = jsonmsg.msgtype;
										var msg = jsonmsg.msg;
										var fromuid = jsonmsg.fromuid; 
										var fromnickname = jsonmsg.fromnickname;
										var fromavatar = jsonmsg.fromavatar;
										var touid = jsonmsg.touid; 
										var tonickname = jsonmsg.tonickname;
										var toavatar = jsonmsg.toavatar;
										var unreadMessageCount = jsonmsg.unreadMessageCount;
										var uid = fromuid == myuid ? touid : fromuid;
										var nickname = fromuid == myuid ? tonickname : fromnickname;
										var avatar = fromuid == myuid ? toavatar : fromavatar;
										var msg_item = {"targetId":jsonmsg.targetId,"senderUserId":jsonmsg.senderUserId,"createtime":sj(ret.data[item].createtime),"uid":uid,"nickname":nickname,"avatar":avatar,"msgtype":msgtype,"msg":msg,"unreadMessageCount":unreadMessageCount};
										chatdialog.push(msg_item);
									}	
								}
								//console.log(JSON.stringify(chatdialog));
										
								//渲染页面
								UpdateList('chatlist','chatlist_template',chatdialog,false);
							}
							else
							{
								UpdateList('chatlist','chatlist_template',[],false);
							}
						} else {
							console.log(JSON.stringify(err))
						}
					})




					
				}
			});
			
		};
		//储存会话
		function Saverecord(uid,content,createtime) {
			eliminaterecord(uid);//清楚以前的会话
			if(createtime==0)
			{
				createtime = new Date().getTime();
			}
			var dialogname = '#'+myuid+'and'+uid+'#';
			db.executeSql({
				name : 'record',
				sql : "insert into chatdialogs(dialogname,content,createtime) values('" + dialogname + "','" + content + "'," + createtime + ")"
			});
			ReadChatDialog();//刷新消息列表;
		};
		function eliminaterecord(uid) {
			var dialogname = '#'+myuid+'and'+uid+'#';
			//alert("delete from chatdialog where dialogname='" + dialogname + "'");
			db.executeSql({
				name : 'record',
				sql : "delete from chatdialogs where dialogname='" + dialogname + "'"
			});
		};
		function updaterecord(uid) {
			//更新某条会话
			var dialogname = '#'+myuid+'and'+uid+'#';
			db.selectSql({
				name : 'record',
				sql : "select * from chatdialogs where dialogname='" + dialogname + "' order by ID desc"
			}, function(ret, err) {
				if (ret) {
					if (ret.data != '') {
						var content = ret.data[0].content;
						var jsonmsg = $api.strToJson(content); 
						jsonmsg.unreadMessageCount = 0;
						var ncontent = $api.jsonToStr(jsonmsg);
						
						db.executeSql({
							name : 'record',
							sql : "update chatdialogs set content='"+ncontent+"' where dialogname='" + dialogname + "'"
						});
					}
				}
			});
			//alert("delete from chatdialog where dialogname='" + dialogname + "'");
			db.executeSql({
				name : 'record',
				sql : "delete from chatdialogs where dialogname='" + dialogname + "'"
			});
		};
		function eliminatechatlog(uid) {
			//清楚聊天记录
			var dialogname = '#'+myuid+'and'+uid+'#';
			//alert("delete from chatdialog where dialogname='" + dialogname + "'");
			db.executeSql({
				name : 'record',
				sql : "delete from chatlogs where dialogname='" + dialogname + "'"
			});
		};
		function chatdialoglist() {
			UpdateList('chatlist','chatlist_template',[],false);
			//会话列表
			rong.getConversationList(function(ret, err) {
				//alert(JSON.stringify(ret));
				if (ret.status == 'success') {
					var chatdialog = [];
					if(ret.result.length > 0)
					{
						for(var item in ret.result){
							if(ret.result[item])
							{
								console.log(JSON.stringify(ret.result[item]));
								var msg = ret.result[item].latestMessage.text;
								var msgtype = 1;
								if (ret.result[item].objectName == 'RC:TxtMsg') {
									msgtype = 1;
								} else if (ret.result[item].objectName == 'RC:ImgMsg') {
									msgtype = 2;
									msg = '[图像消息]';
								} else if (ret.result[item].objectName == 'RC:VcMsg') {
									msgtype = 3;
									msg = '[语音消息]';
								} else if (ret.result[item].objectName == 'RC:VCSummary') {
									if(ret.result[item].latestMessage.mediaType == 1) {
										msgtype = 4;
									}
									else
									{
										msgtype = 5;
									}
									msg = '通话时长 '+formatSeconds(ret.result[item].latestMessage.duration / 1000);
								} else if (ret.result[item].objectName == 'RC:LBSMsg') {
									msgtype = 6;
									msg = '[位置]';
								}
								if(msgtype!=4 && msgtype!=5) {
									//非音视频信息写入本地记录
									var extramsg = $api.strToJson(ret.result[item].latestMessage.extra);
									//alert(ret.result[item].latestMessage.extra);
									var fromuid = extramsg.fromuid; 
									var fromnickname = extramsg.fromnickname;
									var fromavatar = extramsg.fromavatar;
									var unreadMessageCount = ret.result[item].unreadMessageCount;
									
									var touid = extramsg.touid; 
									
									if(touid == myuid || fromuid == myuid) {
										//新增判断20191219
										var tonickname = extramsg.tonickname;
										var toavatar = extramsg.toavatar;
				
										var uid = fromuid == myuid ? touid : fromuid;
										var nickname = fromuid == myuid ? tonickname : fromnickname;
										var avatar = fromuid == myuid ? toavatar : fromavatar;
										
										
										var newchat = {
											"msgid":ret.result[item].latestMessageId,
											"createtime":getdate(ret.result[item].sentTime),
											"msgtype":msgtype,
											"msg":msg,
											"unreadMessageCount":unreadMessageCount
											
										};
										newchat.targetId = ret.result[item].targetId;
										newchat.senderUserId = ret.result[item].senderUserId;
										newchat.fromuid = fromuid;
										newchat.fromavatar =  fromavatar;
										newchat.fromnickname = fromnickname;
										newchat.touid = touid;
										newchat.toavatar =  toavatar;
										newchat.tonickname = tonickname;
										Saverecord(uid,$api.jsonToStr(newchat),ret.result[item].sentTime);
									}
								}
								else if(msgtype==50)
								{
									var fromuid = "", touid = ""; 
									if(ret.result[item].senderUserId == myuid)
									{
										fromuid = myuid;
										touid = ret.result[item].targetId;
									}
									else
									{
										fromuid = ret.result[item].senderUserId;
										touid = myuid;
									}
									var uid = fromuid == myuid ? touid : fromuid;
									var newchat = {
										"msgid":ret.result[item].latestMessageId,
										"createtime":getdate(ret.result[item].sentTime),
										"msgtype":msgtype,
										"msg":msg,
										"unreadMessageCount":unreadMessageCount
										
									};
									newchat.targetId = ret.result[item].targetId;
									newchat.senderUserId = ret.result[item].senderUserId;
									newchat.fromuid = fromuid;
									newchat.fromavatar =  "";
									newchat.fromnickname = "";
									newchat.touid = touid;
									newchat.toavatar =  "";
									newchat.tonickname = "";
									Saverecord(uid,$api.jsonToStr(newchat),ret.result[item].sentTime);
								}
								else
								{
									console.log(2);
									ReadChatDialog();
								}
							}	
						}
						
						console.log(JSON.stringify(chatdialog));
						
					}
					else
					{
						console.log(1);
						ReadChatDialog();
					}
				}
				else
				{
					ReadChatDialog();
					console.log(3);
					//alert(JSON.stringify(ret));
				}
			})
		}
		
		//时间差计算
		function sj(sj) {
			var nowt = new Date().getTime();
			var a = new Date(parseInt(sj));
			var b = new Date(parseInt(nowt));
			var date1 = Date.parse(format(a, 4));
			var date2 = Date.parse(format(b, 4));
			var xxsj = Math.ceil((date2 - date1) / (60 * 1000))
			if (xxsj <= 1 && xxsj >= 0) {
				return "刚刚";
			} else if (xxsj <= 5 && xxsj > 1) {
				return xxsj + "分钟前";
			} else if (xxsj <= 60 && xxsj > 5) {
				return format(a, 1);
			} else if (xxsj <= 1440 && xxsj > 60) {
				return format(a, 1);
			} else if (xxsj <= 10080 && xxsj > 1440) {
				return format(a, 2);
			} else if (xxsj > 10080) {
				return format(a, 3);
			} else {
				return format(a, 3);
			}
		}
		//格式化时间
		function format(now, type) {
			var show_day = new Array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');
			var year = now.getFullYear().toString();
			var month = (now.getMonth() + 1).toString();
			var day = (now.getDate()).toString();
			var tian = now.getDay().toString();
			var hour = (now.getHours()).toString();
			var minute = (now.getMinutes()).toString();
			var second = (now.getSeconds()).toString();
			if (hour.length == 1) {
				hour = "0" + hour;
			}
			if (minute.length == 1) {
				minute = "0" + minute;
			}
			if (second.length == 1) {
				second = "0" + second;
			}
			if (type == 1) {
				var dateTime = hour + ":" + minute;
			} else if (type == 2) {
				var dateTime = show_day[tian] + " " + hour + ":" + minute
			} else if (type == 3) {
				var dateTime = year + "-" + month + "-" + day
			} else if (type == 4) {
				var dateTime = year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second;
			} else if (type == 5) {
				var dateTime = show_day[tian];
			}
			return dateTime;
		}
		function getdate(timestamp) {
            var now = new Date(timestamp),
			y = now.getFullYear(),
			m = now.getMonth() + 1,
			d = now.getDate();
			return (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 5);
            //return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
        }
		function addChat(chatlist1) {
			//将接受到的消息显示在消息列表最前面
			var chatlist = $api.strToJson(chatlist1);
			var conId = chatlist[0].conversationId;
			var liList = document.getElementById("chatlist").children;
			for (var i = 0; i < liList.length; i++) {
				if($api.attr(liList[i],'data-conid') == conId)
				{
					$api.remove(liList[i]);
				}
				//$api.removeCls(liList[i], 'on')
			}
			for(var item in chatlist){
				chatlist[item].sj = sj(chatlist[item].timestamp);
				chatlist[item].extra = chatlist[item].ext;
				var unreadMessagesCount = 0;
				chatlist[item].unreadCount = unreadMessagesCount;
				chatlist[item].latestMessage = chatlist[item];
			}
			UpdateList('chatlist','chatlist_template',chatlist,true);
		}
		//渲染数据
		function UpdateList(domId,templateId,jsondata,isAppend) {
		
			var act_content = $api.byId(domId);
			var tempFn = doT.template($api.byId(templateId).innerHTML);
			var resultText = tempFn(jsondata);
			//alert(isAppend);
			if(isAppend)
			{
				$api.prepend(act_content, resultText);
			}
			else
			{
				$api.html(act_content, resultText);
			}
			api.parseTapmode();
			addDiyEvent();
		}
		function touchstartF(event) {
			x = event.changedTouches[0].pageX;
			y = event.changedTouches[0].pageY;
			swipeX = true;
			swipeY = true;
		};
		function touchmoveF(event, e) {
			X = event.changedTouches[0].pageX;
			Y = event.changedTouches[0].pageY;
			// 左右滑动
			if (swipeX && Math.abs(X - x) - Math.abs(Y - y) > 0) {
				// 阻止事件冒泡
				event.stopPropagation();
				if (X - x > 10) {
					event.preventDefault();
					e.style.WebkitTransform = "translateX(" + 0 + "px)";
					e.style.transition = "-webkit-transform 300ms ease-in-out";
				}
				if (x - X > 10) {
					event.preventDefault();
					e.style.WebkitTransform = "translateX(" + -60 + "px)";
					e.style.transition = "-webkit-transform 300ms ease-in-out";
				}
				swipeY = false;
			}
			// 上下滑动
			if (swipeY && Math.abs(X - x) - Math.abs(Y - y) < 0) {
				swipeX = false;
			}
		};
			
			
		function toDelete(event, e, targetId) {
			$api.remove(e.parentNode.parentNode);
			var uid = targetId;
			eliminaterecord(uid)
			eliminatechatlog(uid);
			rong.removeConversation({
				conversationType: 'PRIVATE',
				targetId: targetId
			}, function(ret, err) {
				//api.toast({ msg: ret.status });
			});
			
		}
	</script>
</html>